#pragma once

#include "AnimEvaluator.h"
#include <map>

using namespace std;

enum AnimationStatus
{
	Play,Stop,Pause
};

class AnimationController
{
public:
	AnimationController(void);
	~AnimationController(void);
	bool Update(DWORD time);
	void setAnimation(const char* animName) {currentAnim = animName;}
	void SetAnimationStatus(AnimationStatus  st) {state = st;}
	AnimationStatus getAnimationStatus() {return state;}

	void AddAnimation(AnimEvaluator* animation) 
	{
		const char* anName= animation->GetAnimationName();
		if(anName == NULL)
		{
			anName = (const char*) malloc(sizeof(char) * 10);
			itoa(noNameAnim++, const_cast<char*>(anName) ,10);
		}
		Animations[anName] = animation;
	}	


	XMMATRIX* GetCurrentAnimationTransforms() { return Animations[currentAnim]->GetAnimTransformation(); }

	vector<const char*> GetAnimationNames() 
	{
		vector<const char*> resp;
		map<string, AnimEvaluator*>::const_iterator it = Animations.begin();
		for(; it != Animations.end(); it++)
		{		
			resp.push_back(it->first.c_str());
		}
		return resp;
	}

	int GetCurrentAnimationIndex()
	{
		return Animations[currentAnim]->AnimationIndex;
	}

	AnimationController* Clone()
	{
		AnimationController* ac = new AnimationController();
		map<string, AnimEvaluator*>::iterator p;
		for(p = Animations.begin(); p != Animations.end(); p++) 
		{
			ac->AddAnimation(p->second->Clone());
		}
		return ac;
	}

private:			
	map<string, AnimEvaluator*> Animations;
	const char* currentAnim;
	AnimationStatus state;
	int noNameAnim;

};
